import {ref } from 'vue';
// 倒计时

export default function init(time: number = 60, cb?) {
    const big = time 
    const timeShot = ref(0);
    let clear:any = ''
    const clearTime =(val:boolean = false)=> {
        clearInterval(clear)
        clear = ''
        timeShot.value  = 0
        if (val) {
            cb && cb(true)
        }
    }
    const start  = ()=> {
        timeShot.value = big
        clear = setInterval(()=>{
            timeShot.value  -= 1
            if (timeShot.value ===0) {
                clearTime(true)
            }
        }, 1000)
    }
    return {
      timeShot,
      start,
      clearTime
    };
  }
